package cn.panda.edu.controller;

import cn.panda.edu.model.Education;
import cn.panda.edu.service.EducationService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/admin")
@Api(description="教学计划")
public class ManageEducationController {
	@Autowired
	private EducationService educationService;
	
	/**
	 * 
	* @Title: educationFy 
	* @Description: 教学计划展示分页
	* @param @param pageIndex
	* @param @return  
	* @return PageInfo<Education>
	 */
	@ApiOperation(value="教学计划分页" , notes="教学计划展示")//用以指明api名称 
	@RequestMapping(value = "/educationFy",method = RequestMethod.POST)
	@ApiImplicitParam(name="pageIndex", value="页码", required=true, dataType="int",paramType="form")
	public Object educationFy(Integer pageIndex){
		PageInfo<Education> pageInfo=educationService.selectAll(pageIndex, Constant.PAGE_SIZE);
		return ResultDataUtil.resData(200, "", pageInfo);
	}
	
	/**
	 * 
	* @Title: educationSel 
	* @Description: 根据id查询教学计划
	* @param @param educationPlanId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据id查询教学计划" , notes="id查询")//用以指明api名称 
	@ApiImplicitParam(name="educationPlanId", value="教学计划id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/educationSel",method = RequestMethod.POST)
	public Map<String,Object> educationSel(@RequestParam(required=true)Integer educationPlanId){
		Education education = educationService.selectByPrimaryKey(educationPlanId);	
		return ResultDataUtil.resData(200, "", education);		
	}
	
	/**
	 * 
	* @Title: educationDel 
	* @Description: 根据id删除课程
	* @param @param educationPlanId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据id删除课程" , notes="id删除")//用以指明api名称 
	@ApiImplicitParam(name="educationPlanId", value="教学计划id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/educationDel",method = RequestMethod.POST)
	public Map<String,Object> educationDel(@RequestParam(required=true)Integer educationPlanId){
		Map<String,Object> map=new HashMap<>();
		int i=educationService.deleteByPrimaryKey(educationPlanId);
		if(i>0) {
			map = ResultDataUtil.resData(200, "删除成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "删除失败",null) ;
		}
		return map;		
	}
	
	/**
	 * 
	* @Title: educationDel 
	* @Description: 根据id修改课程
	* @param @param educationPlanId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据id修改课程" , notes="id修改")//用以指明api名称 
	@ApiImplicitParam(name="record", value="课程对象", required=true, dataType="Education",paramType="form")	
	@RequestMapping(value = "/educationUp",method = RequestMethod.POST)
	public Map<String,Object> educationUp(@RequestParam(required=true)Education record){
		Map<String,Object> map=new HashMap<>();
		int i =  educationService.updateByPrimaryKeySelective(record);
		if(i>0) {
			map = ResultDataUtil.resData(200, "更新成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "删除成功",null) ;
		}
		return map;		
	}
	/**
	 * 
	* @Title: educationAdd 
	* @Description: 添加教学信息计划 
	* @param @param record
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="添加教学计划" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="record", value="教学计划对象", required=true, dataType="Education",paramType="form")	
	@RequestMapping(value = "/educationAdd",method = RequestMethod.POST)
	public Map<String,Object> educationAdd(@RequestParam(required=true)Education record){
		Map<String,Object> map=new HashMap<>();
		int i=educationService.insertSelective(record);
		if(i>0) {
			map = ResultDataUtil.resData(200, "添加成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "添加失败",null) ;
		}
		return map;		
	}
}
